package com.jcl.recruit.depart.logic;

import com.jcl.core.constants.Constant;
import com.jcl.recruit.core.constants.Constants;
import com.jcl.recruit.org.mapper.DepartmentMapper;
import com.jcl.recruit.org.model.Department;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @ClassName DepartmentLogic
 * @Description TODO
 * @Author yyliu
 * @Date 2018/9/12 18:49
 * @Version 1.0
 **/
@Component
public class DepartmentLogic implements DepartmentMapper {

    @Autowired
    private DepartmentMapper departmentMapper;

    public Department addRoot(String fullName, Integer companyId, String corpCode){
        Department department = new Department();
        department.setFullname(fullName);
        department.setShortname(fullName);
        department.setSubcompanyId(companyId);
        department.setCorpCode(corpCode);
        department.setSuperId(Constants.DepartmentInfo.ROOT_SUPER_ID);
        department.setCode(Constant.NUMBER_0 + "");
        department.setShoworder(Constant.NUMBER_1);
        departmentMapper.add(department);
        return department;
    }

    @Override
    public List<Department> selectDepartmentListsBySupperIdAndCompanyIdAndKeyword(Integer superId, Integer subcompanyId, String keyword) {
        return departmentMapper.selectDepartmentListsBySupperIdAndCompanyIdAndKeyword(superId,subcompanyId,keyword);
    }

    @Override
    public Department findRootByCorpCode(String corpCode, Integer superId) {
        return departmentMapper.findRootByCorpCode(corpCode, superId);
    }

    @Override
    public Department selectPrimarykeyById(Integer id) {
        return departmentMapper.selectPrimarykeyById(id);
    }

    @Override
    public List<Department> selectAllDepartmentsBySubaccountId(Integer superId,Integer subcompanyId) {
        return departmentMapper.selectAllDepartmentsBySubaccountId(superId,subcompanyId);
    }

    @Override
    public int add(Department department) {
        return departmentMapper.add(department);
    }
}
